#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QClipboard>
#include <QDebug>
#include <QRegularExpression>

#define PATTERN R"(pt_key=(.*?);([\s\S]*?)pt_pin=(.*?);)"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_plainTextEdit_textChanged()
{
     auto& textEdit = *this->ui->plainTextEdit;
     auto& lineEdit = *this->ui->lineEdit;
     auto& tips = this->ui->tips;

     QRegularExpression re{PATTERN};
     auto match = re.match(textEdit.toPlainText());
     if(match.hasMatch()){
         tips->setState(true);
         tips->setContent("匹配成功!");
         lineEdit.setText(match.captured(0));
     }else{
         tips->setState(false);
         tips->setContent("匹配失败!");
     }

//     qDebug()<<textEdit.toPlainText();

     // parse
}


void MainWindow::on_pushButton_clicked()
{
    QGuiApplication::clipboard()->setText(ui->lineEdit->text());
    ui->tips->setContent("复制成功!");
    ui->tips->repaint();
}

